//
//  ProfileVc.m
//  HTP
//
//  Created by admin on 15/11/15.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "ProfileVc.h"
#import "UIScrollView+UITouch.h"
#import "NSDate+FSExtension.h"
#import "ProfileModel.h"
#import "UserVM.h"
#import "CDPPickerView.h"
#import "LocationViewController.h"
#define HeadImagWidth 80
#define OneHeight 45
@interface ProfileVc ()<UITextFieldDelegate,UIImagePickerControllerDelegate,UIActionSheetDelegate,UINavigationControllerDelegate,CDPPickerViewDelegate,LocationViewControllerDelegate>
@property (nonatomic,retain) UIScrollView *backView;

@property (nonatomic,retain) UITextField *nameTextfield;
@property (nonatomic,retain) UITextField *detailAddressTextfield;
@property (nonatomic,retain) UITextField *schoolTextfield;
@property (nonatomic,retain) UITextField *bottomTextfield;
@property (nonatomic,retain) UITextField *localTextfield;
@property (nonatomic,retain) UITextField *editTextfield;

@property (nonatomic,retain) UILabel     *sexyLbl;
@property (nonatomic,retain) UILabel     *ageLbl;
@property (nonatomic,retain) UIImageView *headImage;

@property (nonatomic,retain) ProfileModel *profileModel;
@property (nonatomic,assign) NSInteger     updateCount;//头像更新次数

@property (nonatomic,retain) CDPPickerView *sexPick;
@property (nonatomic,retain) UIView *dateView;
@property (nonatomic,retain) UIDatePicker *datePick;
@end

@implementation ProfileVc

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.userInteractionEnabled = YES;
    [self.view addSubview:self.backView];
    [self _initView];
}
-(void)viewWillAppear:(BOOL)animated{
    _profileModel = [ProfileModel mj_objectWithKeyValues:[USERCONTENT getDefaultUser]];
    [self setProfileData];
    [self addCustomBackBase];
    [self addCustomTitleWithTitle:@"基本信息"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHiden:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
//TODO:UI绘制
-(void)_initView{
    [self _initLine];
    _headImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth / 2.0 - 40 , 35 ,80 , 80)];
    _headImage.userInteractionEnabled = YES;
    [_headImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeIcon)]];
    [self.backView addSubview:_headImage];
    
    UILabel *naemLbl = [self getNormolLabel];
    [naemLbl setText:@"姓 名"];
    [naemLbl setFrame:CGRectMake(5, 151, 60, OneHeight - 2)];
    [self.backView addSubview:naemLbl];
    
    _nameTextfield = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(naemLbl.frame) + 20, 151 , ScreenWidth - CGRectGetMaxX(naemLbl.frame) -20, OneHeight -2)];
    _nameTextfield.textAlignment = _TEXT_ALIGN_LEFT;
    _nameTextfield.textColor = [UIColor blackColor];
    _nameTextfield.font = [UIFont systemFontOfSize:15];
    _nameTextfield.delegate = self;
    _nameTextfield.returnKeyType = UIReturnKeyDone;
    [self.backView addSubview:_nameTextfield];
    
    //性别
    UILabel *sexLbl = [self getNormolLabel];
    [sexLbl setText:@"性 别"];
    [sexLbl setFrame:CGRectMake(5, 151 + OneHeight, 60, OneHeight - 2)];
    [self.backView addSubview:sexLbl];
    
    _sexyLbl = [self getNormolLabel];
    [_sexyLbl setFrame:CGRectMake(CGRectGetMaxX(sexLbl.frame) + 20, 151 + OneHeight, ScreenWidth - CGRectGetMaxX(sexLbl.frame) -20, OneHeight -2)];
    _sexyLbl.textAlignment = _TEXT_ALIGN_LEFT;
    _sexyLbl.userInteractionEnabled = YES;
    [_sexyLbl addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectSexy:)]];
    [self.backView addSubview:_sexyLbl];
    //年纪
    UILabel *ageLbl = [self getNormolLabel];
    [ageLbl setText:@"年 龄"];
    [ageLbl setFrame:CGRectMake(5, 151 + OneHeight * 2.0, 60, OneHeight - 2)];
    [self.backView addSubview:ageLbl];
    
    _ageLbl = [self getNormolLabel];
    [_ageLbl setFrame:CGRectMake(CGRectGetMaxX(ageLbl.frame) + 20, 151 + OneHeight * 2.0, ScreenWidth - CGRectGetMaxX(ageLbl.frame) -20, OneHeight -2)];
    _ageLbl.textAlignment = _TEXT_ALIGN_LEFT;
    _ageLbl.userInteractionEnabled = YES;
    [_ageLbl addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectUserAge)]];
    [self.backView addSubview:_ageLbl];
    //地址
    UILabel *adressLbl = [self getNormolLabel];
    [adressLbl setText:@"地 址"];
    [adressLbl setFrame:CGRectMake(5, 151 + OneHeight * 3.5, 60, OneHeight - 2)];
    [self.backView addSubview:adressLbl];
    [self _initAddressTextfield];
    //学校
    UILabel *schoolLbl = [self getNormolLabel];
    [schoolLbl setText:@"所在学校"];
    [schoolLbl setFrame:CGRectMake(5, 151 + OneHeight * 5.0, 60, OneHeight - 2)];
    [self.backView addSubview:schoolLbl];
    
    _schoolTextfield = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(schoolLbl.frame) + 20, 151 + OneHeight * 5.0 , ScreenWidth - CGRectGetMaxX(schoolLbl.frame) -20, OneHeight -2)];
    _schoolTextfield.textAlignment = _TEXT_ALIGN_LEFT;
    _schoolTextfield.textColor = [UIColor blackColor];
    _schoolTextfield.font = [UIFont systemFontOfSize:15];
    _schoolTextfield.delegate = self;
    _schoolTextfield.returnKeyType = UIReturnKeyDone;
    [self.backView addSubview:_schoolTextfield];
    //座右铭
    UILabel *bottomLbl = [self getNormolLabel];
    [bottomLbl setText:@"座右铭"];
    [bottomLbl setFrame:CGRectMake(5, 151 + OneHeight * 6.0, 60, OneHeight - 2)];
    [self.backView addSubview:bottomLbl];
    
    _bottomTextfield = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(bottomLbl.frame) + 20, 151 + OneHeight * 6.0 , ScreenWidth - CGRectGetMaxX(bottomLbl.frame) -20, OneHeight -2)];
    _bottomTextfield.textAlignment = _TEXT_ALIGN_LEFT;
    _bottomTextfield.textColor = [UIColor blackColor];
    _bottomTextfield.font = [UIFont systemFontOfSize:15];
    _bottomTextfield.delegate = self;
    _bottomTextfield.returnKeyType = UIReturnKeyDone;
    [self.backView addSubview:_bottomTextfield];
}
//TODO:初始化线
-(void)_initLine{
    for(int i = 0 ; i < 8 ; i++){
        CGFloat lineX = 0 ;
        CGFloat lineW = ScreenWidth;
        if (i == 4) {
            lineW = ScreenWidth - 80;
            lineX = 80;
        }
        UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(lineX, 150 + OneHeight*i, lineW, 1)];
        [line setImage:[UIImage imageNamed:@"line"]];
        [self.backView addSubview:line];
        if (i == 7) {
            [self.backView setContentSize:CGSizeMake(ScreenWidth, CGRectGetMaxY(line.frame)+20 > ScreenHeihgt -NavHe + 10? CGRectGetMaxY(line.frame)+20:ScreenHeihgt - NavHe + 10 )];
        }
    }
}
//TODO:初始化地址栏
-(void)_initAddressTextfield{
    _localTextfield = [[UITextField alloc] initWithFrame:CGRectMake(_nameTextfield.frame.origin.x, 151 + OneHeight * 3.0, ScreenWidth - _nameTextfield.frame.origin.x -10, OneHeight - 2)];
    _localTextfield.placeholder = @"获取定位信息";
    _localTextfield.textAlignment = _TEXT_ALIGN_LEFT;
    _localTextfield.font = [UIFont systemFontOfSize:14];
    [_localTextfield setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [_localTextfield setValue:[UIFont systemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, (OneHeight - 2) / 2.0 + 10, OneHeight - 2)];
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, (OneHeight - 2) / 4.0, (OneHeight - 2) / 2.0, (OneHeight - 2) / 2.0)];
    imageV.contentMode = UIViewContentModeScaleAspectFit;
    imageV.image = [UIImage imageNamed:@"address"];
    [leftView addSubview:imageV];
    _localTextfield.leftView = leftView;
    _localTextfield.leftViewMode = UITextFieldViewModeAlways;
    
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, (OneHeight - 2) / 2.0 , OneHeight - 2)];
    UIImageView *rightImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, (OneHeight - 2) / 4.0, (OneHeight - 2) / 2.0, (OneHeight - 2) / 2.0)];
    rightImage.contentMode = UIViewContentModeScaleAspectFit;
    rightImage.image = [UIImage imageNamed:@"forward"];
    [rightView addSubview:rightImage];
    _localTextfield.rightView = rightView;
    _localTextfield.rightViewMode = UITextFieldViewModeAlways;
    _localTextfield.enabled = NO;
    UIButton *selectLocal = [[UIButton alloc] initWithFrame:CGRectMake(_nameTextfield.frame.origin.x, 151 + OneHeight * 3.0, ScreenWidth - _nameTextfield.frame.origin.x -10, OneHeight - 2)];
    [selectLocal addTarget:self action:@selector(getLocation) forControlEvents:UIControlEventTouchUpInside];
    [selectLocal setBackgroundColor:[UIColor clearColor]];
    [self.backView addSubview:selectLocal];
    [self.backView bringSubviewToFront:selectLocal];
    [self.backView addSubview:_localTextfield];
    
    _detailAddressTextfield = [[UITextField alloc] initWithFrame:CGRectMake(_nameTextfield.frame.origin.x, 151 + OneHeight * 4.0, ScreenWidth - _nameTextfield.frame.origin.x -10, OneHeight - 2)];
    _detailAddressTextfield.placeholder = @"补充详细地址(如门牌号/楼层号等)";
    _detailAddressTextfield.textAlignment = _TEXT_ALIGN_LEFT;
    _detailAddressTextfield.delegate = self;
    _detailAddressTextfield.font = [UIFont systemFontOfSize:15];
    [_detailAddressTextfield setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [_detailAddressTextfield setValue:[UIFont systemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];
    _detailAddressTextfield.returnKeyType = UIReturnKeyDone;
    [_detailAddressTextfield bringSubviewToFront:self.view];
    [self.backView addSubview:_detailAddressTextfield];
}
//TODO:重写get方法
-(UIScrollView *)backView{
    if (!_backView) {
        _backView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeihgt - NavHe)];
        [_backView setBackgroundColor:[UIColor whiteColor]];
        _backView.userInteractionEnabled = YES;
    }
    return _backView;
}
//TODO:性别选择
-(CDPPickerView *)sexPick{
    NSArray *dataArray;
    if([_profileModel.prChildSex isEqualToNumber:@2]){
        dataArray = [[NSArray alloc] initWithObjects:@"女",@"男", nil];
    }else{
        dataArray = [[NSArray alloc] initWithObjects:@"男",@"女", nil];
    }
    if (_sexPick == nil) {
        _sexPick = [[CDPPickerView alloc] initWithDataArr:dataArray selectTitle:@"性别" rowHeight:40 delegate:self delegateView:self.view];
    }
    return _sexPick;
}
//TODO:初始化选择日期的视图
-(UIView *)dateView{
    if (!_dateView) {
        _dateView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0,  250)];
        _dateView.backgroundColor = RGBCOLOR(220, 220, 220, 1);
        [_dateView addSubview:self.datePick];
        UIButton *sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 60, 4, 50, 30)];
        [sureBtn setTitle:@"确定" forState:UIControlStateNormal];
        [sureBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [sureBtn setBackgroundColor:RGBCOLOR(220, 220, 220, 1)];
        [sureBtn addTarget:self action:@selector(commitUserBir) forControlEvents:UIControlEventTouchUpInside];
        [_dateView addSubview:sureBtn];
    }
    return _dateView;
}
//TODO:初始化、懒加载datePick
- (UIDatePicker *)datePick{
    if (_datePick==nil) {
        _datePick = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,34, self.view.frame.size.width, 216)];
        NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh"];
        UIView *v = [[_datePick subviews] objectAtIndex:0];
        [v setBackgroundColor:[UIColor whiteColor]];
        [_datePick setLocale:locale];
        _datePick.maximumDate = [NSDate date];
        _datePick.datePickerMode = UIDatePickerModeDate;
        _datePick.tag = -1;
        //设置datepicker初始时选中的时间
        if(![self.profileModel.userBirth isEqualToString:@""]){
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:DATEFORMATT];
            NSDate *date = [dateFormatter dateFromString:self.profileModel.userBirth];
            _datePick.date = date;
        }
        [_datePick addTarget:self action:@selector(dateChange) forControlEvents:UIControlEventValueChanged];
    }
    return _datePick;
}
- (void)dateChange {
    NSDate *date = _datePick.date;
    _ageLbl.text = [NSString stringWithFormat:@"%ld",(long)[[NSDate date] fs_yearsFrom:date]];
}
//TODO:键盘相关事件
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.backView endEditing:YES];
//    [self.sexPick popPicker];
    [self hiddenDatePickView];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.backView endEditing:YES];
    return YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
    _editTextfield = textField;
    [self.sexPick popPicker];
    if (self.navigationItem.rightBarButtonItems != nil) {
        return;
    }
    [self addCustomRightWithAction:@selector(updateProfile) title:@"完成" normalImg:nil selectImg:nil];
}
-(void) keyboardWillHiden:(NSNotification *)notification{
    [UIView animateWithDuration:0.5 animations:^{
        [self.backView setContentOffset:CGPointMake(0, 0)];
    }];
}
-(void)keyboardWillShow:(NSNotification *)notification{
    NSDictionary *userInfo = [notification userInfo];
    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    CGFloat animationDuration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    CGFloat bottom = CGRectGetMaxY(_editTextfield.frame)+OneHeight;
    CGFloat keyboardOffset = CGRectGetHeight(keyboardRect);
    int offset = bottom + keyboardOffset  - ScreenHeihgt + NavHe;
    if(offset>0){
        [UIView animateWithDuration:animationDuration animations:^{
            [self.backView setContentOffset:CGPointMake(0, offset)];
        }];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//TODO:Action
//TODO:更新个人信息
-(void)updateProfile {
    UserVM *userVM = [[UserVM alloc] init];
    [userVM setBlockWithReturnBlock:^(id returnValue) {
        self.navigationItem.rightBarButtonItems = nil;
        [self changeProfile];
        [self showSVProgressSuccess:@"修改成功"];
    } WithErrorBlock:^(id errorCode) {
        [self showSVProgressFailed:@"保存失败"];
    } WithFailureBlock:^{
        [self showSVProgressFailed:INTERFACE_FAILURE_CHIN];
    }];
    NSNumber *prChildSex;
    if([_sexyLbl.text isEqualToString:@"男"]){
        prChildSex = [NSNumber numberWithInt:1];
    }else if([_sexyLbl.text isEqualToString:@"女"]){
        prChildSex = [NSNumber numberWithInt:2];
    }
    [self showSvprogress:@"保存数据"];
    [userVM profileUpdate:[NSString stringWithFormat:@"%@",self.profileModel.prId] prChilrName:_nameTextfield.text == nil?@"":_nameTextfield.text prChildSex:[NSString stringWithFormat:@"%@",prChildSex] userBirth:_profileModel.userBirth==nil?@"":_profileModel.userBirth prChildSchool:_schoolTextfield.text prAddr:_detailAddressTextfield.text == nil ? @"":_detailAddressTextfield.text prChildPhoto:@"" prMotto:_bottomTextfield.text == nil ? @"":_bottomTextfield.text];
}
-(void)changeProfile{
    NSNumber *prChildSex;
    if([_sexyLbl.text isEqualToString:@"男"]){
        prChildSex = [NSNumber numberWithInt:1];
    }else if([_sexyLbl.text isEqualToString:@"女"]){
        prChildSex = [NSNumber numberWithInt:2];
    }
    self.profileModel.prChildName = _nameTextfield.text;
    self.profileModel.prChildSex = [NSNumber numberWithInt:[prChildSex intValue]];
    self.profileModel.prChildSchool = _schoolTextfield.text;
    self.profileModel.prAddr = _detailAddressTextfield.text;
    self.profileModel.prMotto =_bottomTextfield.text;
    NSDictionary *userDic = [[NSDictionary alloc] initWithDictionary:self.profileModel.mj_keyValues];
    [USERCONTENT setUserBean:userDic];
    [[NSNotificationCenter defaultCenter] postNotificationName:CHANGEPROFILE object:nil];
}
//TODO:性别相关
-(void)selectSexy:(id)sender{
    [self.backView endEditing:YES];
    [self hiddenDatePickView];
    [self.sexPick pushPicker];
    if (self.navigationItem.rightBarButtonItems != nil) {
        return;
    }
    [self addCustomRightWithAction:@selector(updateProfile) title:@"完成" normalImg:nil selectImg:nil];
}
//TODO:头像相关
-(void)uploadImage:(NSString *)imgString{
    UserVM *userVM = [[UserVM alloc] init];
    NSString *fileName = [NSString stringWithFormat:@"IOS%@.png",[[NSDate date] fs_stringWithFormat:@"yyyyMMddhhmmssss"]];
    [userVM setBlockWithReturnBlock:^(id returnValue) {
        [self changeUserImage:fileName];
        [self hiddenMbProgress];
    } WithErrorBlock:^(id errorCode) {
        DLog(@"");
        [self hiddenMbProgress];
    } WithFailureBlock:^{
        DLog(@"");
        [self hiddenMbProgress];
    }];
    [self showMbProgress:@""];
    [userVM imageUpload:imgString andFileName:fileName];
}
//TODO:年龄相关
-(void)selectUserAge{
    if (self.navigationItem.rightBarButtonItems == nil) {
        [self addCustomRightWithAction:@selector(updateProfile) title:@"完成" normalImg:nil selectImg:nil];
    }
    [self.backView endEditing:YES];
    if (!self.dateView.superview) {
        [self.view addSubview:self.dateView];
    }
   
    [UIView animateWithDuration:0.5 animations:^{
        [self.sexPick popPicker];
        CGFloat offset = CGRectGetMaxY(_ageLbl.frame)+OneHeight+250-ScreenHeihgt+NavHe;
        [self.backView setContentOffset:CGPointMake(0, offset)];
        [self.dateView setFrame:CGRectMake(0, ScreenHeihgt - NavHe - 250, ScreenWidth, 250)];
    }];
}
-(void)commitUserBir{
    NSDate *date = _datePick.date;
    _ageLbl.text = [NSString stringWithFormat:@"%ld",(long)[[NSDate date] fs_yearsFrom:date]];
    _profileModel.userBirth = [date fs_stringWithFormat:DATEFORMATT];
    [self hiddenDatePickView];
}
-(void)hiddenDatePickView{
    [UIView animateWithDuration:0.5 animations:^{
        [self.backView setContentOffset:CGPointMake(0, 0)];
        [self.dateView setFrame:CGRectMake(0, ScreenHeihgt, ScreenWidth, _dateView.frame.size.height)];
    }];
}
//TODO:更改用户头像
-(void)changeUserImage:(NSString *)url{
    _updateCount ++;
    UserVM *userVM = [[UserVM alloc] init];
    [userVM setBlockWithReturnBlock:^(id returnValue) {
        _profileModel.userPhoto = url;
        NSDictionary *userDic = [[NSDictionary alloc] initWithDictionary:_profileModel.mj_keyValues];
        [USERCONTENT setUserBean:userDic];
        [[NSNotificationCenter defaultCenter] postNotificationName:CHANGEPROFILE object:nil];
    } WithErrorBlock:^(id errorCode) {
        if (_updateCount > 3) {
            return ;
        }
        [self changeUserImage:url];
    } WithFailureBlock:^{
        [self showSVProgressFailed:@"网络错误"];
    }];
    [userVM updateUserPhoto:[NSString stringWithFormat:@"%@",_profileModel.userId] photoUrl:url];
}
//TODO:头像点击触发事件
- (void)changeIcon {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"相机",@"相册", nil];
    [actionSheet showInView:self.view];
}

//TODO:actionSheet Delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) { //调用系统相机
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:imagePicker animated:YES completion:nil];
    } else if(buttonIndex == 1) { //调用系统相册
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}
//TODO:imagePicker Delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    UIImage *imageData = info[@"UIImagePickerControllerEditedImage"];
    NSData *image = UIImageJPEGRepresentation(imageData, 0.3);
    //设置
    [picker dismissViewControllerAnimated:YES completion:^{
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
        if (imageData == nil) {
            return ;
        }
         _headImage.image = imageData;
        [self uploadImage:(NSString *)image];
    }];
}
//TODO:CDPick  delegate
-(void)CDPPickerViewDidClickConfirm:(NSString *)confirmString{
    _sexyLbl.text = confirmString;
}
//TODO:设置数据
-(void)setProfileData{
    [_headImage setNormalImageUrl:_profileModel.userPhoto anplaceholder:@"m_user_z"];
    _nameTextfield.text = _profileModel.prChildName;
    _sexyLbl.text = @"男";
    if ([_profileModel.prChildSex integerValue] == 2) {
        _sexyLbl.text = @"女";
    }
    _ageLbl.text = [NSString stringWithFormat:@"%ld",(long)-[[NSDate fs_dateFromString:_profileModel.userBirth format:DATEFORMATT] fs_yearsFrom:[NSDate date]]];
    _schoolTextfield.text = _profileModel.prChildSchool;
    _detailAddressTextfield.text = _profileModel.prAddr;
    _bottomTextfield.text = _profileModel.prMotto;
}

//TODO:跳转到下一页面 获取定位信息
- (void)getLocation {
    LocationViewController *locaVc = [[LocationViewController alloc] init];
    locaVc.delegate = self;
    [self.navigationController pushViewController:locaVc animated:YES];
}

//TODO:LocationViewControllerDelegate
-(void)passLocation:(NSString *)name andDetail:(NSString *)detail {
    DLog(@"%@=====%@",name,detail);
    _localTextfield.text = name;
    self.detailAddressTextfield.text = detail;
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
